<?php 
/**
 * 活动模块
 */
class Module_activity{
	/**
	 * 构造函数
	 */
	function __construct(){
	
	}
	function index() {
		return $this->telephone();
	}
	/**
	 * 我要报名，申请话费补贴
	 */
	function draw(){
		$uin = sessionInfo('uin');
		
		//判断时间是否在（10，19）号范围内
		$day=date('d',time());
		if(in_array($day,range(10,19)) === false){
			return View::error('现在不是活动报名时间，每月10-19号报名');
		} 
		$smarty = loadSmarty();
		
		loadLib('Activity');
		$draw=Activity::getDraw($uin);
		
		//检验是否已经报名
		if(!empty($draw['id'])){
			return View::success('你已参加过报名，请不要重复操作，留意公布期(20-31)中奖名单' , array(
			array(
				'name' => '返回活动首页 ',
				'url' => SITEURL . '/?m=activity&amp;sid=' . SessionInfo('skey'),
			)
			));
		}
		$code = Activity::addDraw($uin);
		if($code === 0) {
			loadLib('SysMsg');
			SysMsg::sendSystem($uin , array(
			'send_uin' => $uin,
			) , 1003);	
			return View::success('报名成功，请留意公布期(20-31)中奖名单' , array(
			array(
				'name' => '返回活动首页 ',
				'url' => SITEURL . '/?m=activity&amp;sid=' . SessionInfo('skey'),
			)
			));
		} else {
			return View::error('操作失败' , $code);
		}
	}
	/**
	 * 报名状况
	 */
	function status(){
		$page = isset($_GET['page']) ? intval($_GET['page']) : null;
		$uin = sessionInfo('uin');
		$smarty = loadSmarty();
		
		//获取报名数据
		loadLib('Activity');
		
		//获取个人数据总量
		$activity_count = Activity::getOneCount($uin);
		
		//设置每行10条数据
		$per_page = 10;
		if($page <= 0){
			$page = 1;
		}
		//获取个人报名数据
		$draw=Activity::getAllDraw($uin,$page,$per_page);
		
		//print_r($draw);
		
		$smarty->assign('draw' , $draw);
		$smarty->assign('activity_count' , $activity_count);
		$smarty->assign('per_page' , $per_page);
		return $smarty->fetch('activity/index.tpl.php');
	}
	/**
	 * 所有中奖用户
	 */
	function lottery(){
		$page = isset($_GET['page']) ? intval($_GET['page']) : null;
		$uin = sessionInfo('uin');
		$smarty = loadSmarty();
		
		//获取数据
		loadLib('Activity');
		
		//获取中奖人数总量
		$activity_count = Activity::getLotteryCount();
		
		//设置每行10条数据
		$per_page = 10;
		if($page <= 0){
			$page = 1;
		}
		//获取个人报名数据
		$draw=Activity::getAllLottery($uin,$page,$per_page);
		
		//print_r($draw);
		
		$smarty->assign('draw' , $draw);
		$smarty->assign('activity_count' , $activity_count);
		$smarty->assign('per_page' , $per_page);
		return $smarty->fetch('activity/lottery.tpl.php');
	}
	/**
	 * 邀请得金币,介绍页面
	 */
	function referral(){
		$smarty = loadSmarty();
		
		return $smarty->fetch('activity/referral.tpl.php');
	}
	/**
	 * 话费补贴,介绍页面
	 */
	function telephone(){
		$smarty = loadSmarty();
		
		return $smarty->fetch('activity/telephone.tpl.php');
	}
}

# end of script